package com.situ.mymall.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.situ.mymall.mapper.ShippingMapper;
import com.situ.mymall.pojo.entity.Shipping;
import com.situ.mymall.pojo.query.ShippingQuery;
import com.situ.mymall.service.IShippingService;
import com.situ.mymall.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ShippingServiceImpl implements IShippingService {

    @Autowired
    private ShippingMapper shippingMapper;

    @Override
    public PageResult list(ShippingQuery shippingQuery) {
        PageHelper.startPage(shippingQuery.getPage(), shippingQuery.getLimit());
        List<Shipping> list = shippingMapper.list(shippingQuery);
        PageInfo pageInfo = new PageInfo(list);
        int totalCount = (int) pageInfo.getTotal();

        return PageResult.ok(totalCount,list);
    }

    /*insert会将数据表所有字段都新增。未手动设置值得，都会被null替代，包括默认值
      insertSelective只新增设置的参数，默认值未修改不会被替换*/
    @Override
    public void add(Shipping shipping) {
        shippingMapper.insertSelective(shipping);
    }

    @Override
    public Shipping selectById(Integer id) {
        return shippingMapper.selectByPrimaryKey(id);
    }

    @Override
    public void update(Shipping shipping) {
        shippingMapper.updateByPrimaryKeySelective(shipping);
    }

    @Override
    public void deleteById(Integer id) {
        shippingMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void deleteAll(Integer[] ids) {
        shippingMapper.deleteAll(ids);
    }

}
